package com.lemon.smartsafetynew.ui.adapter.tank;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafetynew.entity.tank.TankItemVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2018/3/17.
 */

public class TankItemAdapter extends LemonRcvAdapter<TankItemVo> {

    public TankItemAdapter(@Nullable List<TankItemVo> data) {
        super(data);
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new ItemAdapter();
    }

    public class ItemAdapter implements AdapterItem<TankItemVo> {

        @Bind(R.id.icon)
        ImageView icon;
        @Bind(R.id.thing_tv)
        TextView thingTv;
        @Bind(R.id.reserves_tv)
        TextView reservesTv;
        @Bind(R.id.percent_tv)
        TextView percentTv;
        @Bind(R.id.temperature_tv)
        TextView temperatureTv;
        @Bind(R.id.pressure_tv)
        TextView pressureTv;
        @Bind(R.id.deviceID)
        TextView deviceID;
        @Bind(R.id.icon_2)
        ImageView icon2;

        @Override
        public int getLayoutResId() {
            return R.layout.item_tank_recycler_item;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {

        }

        @Override
        public void handleData(TankItemVo tankItemVo, int position) {

            float percent = 0;
            if (tankItemVo.getBili() != null || !"".equals(tankItemVo.getBili())) {
                percent = Float.valueOf(tankItemVo.getBili().replace("%", "")).intValue();
            }
            try {
                ViewGroup.LayoutParams layoutParams = icon2.getLayoutParams();
                layoutParams.height = CommonUtil.convertDipOrPx(icon2.getContext(), (int) (150 * percent / 100));
                icon2.setLayoutParams(layoutParams);
            } catch (Exception e) {
                e.printStackTrace();
            }

            thingTv.setText("物质：" + CommonUtil.avoidNullString(tankItemVo.getThing()));
            reservesTv.setText("储量：" + CommonUtil.avoidNullString(tankItemVo.getChuliang()));
            percentTv.setText("比例：" + CommonUtil.avoidNullString(tankItemVo.getBili()));
            temperatureTv.setText("温度：" + CommonUtil.avoidNullString(tankItemVo.getTemperature()));
            pressureTv.setText("压力：" + CommonUtil.avoidNullString(tankItemVo.getPressure()));
            deviceID.setText("位号：" + CommonUtil.avoidNullString(tankItemVo.getNum()));

        }
    }
}
